package logic

import (
	"context"
	"hotel/hotelrpc/hotelrpc"

	"hotel/hotelapi/internal/svc"
	"hotel/hotelapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpDataLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpDataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpDataLogic {
	return &UpDataLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpDataLogic) UpData(req *types.UpDataRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.HotelRpc.UserUpdate(l.ctx, &hotelrpc.UserUpdateRequest{
		Mobile:   req.Mobile,
		Password: req.Password,
		Img:      req.Img,
		Name:     req.Name,
		Sex:      req.Sex,
		Intro:    req.Intro,
		Id:       req.Id,
	})
	if err != nil {
		return &types.Response{
			Msg:  "修改失败" + err.Error(),
			Data: nil,
			Code: 500,
		}, nil
	}
	return &types.Response{
		Msg:  "修改成功",
		Data: update,
		Code: 200,
	}, nil
}
